<?php
/*
 module:		简历基础表
 create_time:	2024-03-08 17:10:45
 author:		
 contact:		
*/

namespace app\api\controller;

use app\api\model\Categorydistrict as CategorydistrictModel;
use app\api\model\Resume as ResumeModel;
use app\api\service\ResumeService;
use think\exception\ValidateException;

class Resume extends Common
{


    /**
     * @api {get} /Resume/index 01、首页数据列表
     * @apiGroup Resume
     * @apiVersion 1.0.0
     * @apiDescription  首页数据列表
     * @apiHeader {String} Authorization 用户授权token
     * @apiHeaderExample {json} Header-示例:
     * "Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOjM2NzgsImF1ZGllbmNlIjoid2ViIiwib3BlbkFJZCI6MTM2NywiY3JlYXRlZCI6MTUzMzg3OTM2ODA0Nywicm9sZXMiOiJVU0VSIiwiZXhwIjoxNTM0NDg0MTY4fQ.Gl5L-NpuwhjuPXFuhPax8ak5c64skjDTCBC64N_QdKQ2VT-zZeceuzXB9TqaYJuhkwNYEhrV3pUx1zhMWG7Org"
     * @apiParam (输入参数：) {int}            [limit] 每页数据条数（默认20）
     * @apiParam (输入参数：) {int}            [page] 当前页码
     * @apiParam (输入参数：) {string}        [uid] uid
     * @apiParam (输入参数：) {string}        [display] display
     * @apiParam (输入参数：) {string}        [display_name] display_name
     * @apiParam (输入参数：) {string}        [audit] audit
     * @apiParam (输入参数：) {string}        [stick] stick
     * @apiParam (输入参数：) {string}        [strong_tag] strong_tag
     * @apiParam (输入参数：) {string}        [title] title
     * @apiParam (输入参数：) {string}        [fullname] fullname
     * @apiParam (输入参数：) {string}        [sex] sex
     * @apiParam (输入参数：) {string}        [sex_cn] sex_cn
     * @apiParam (输入参数：) {string}        [nature] nature
     * @apiParam (输入参数：) {string}        [nature_cn] nature_cn
     * @apiParam (输入参数：) {string}        [trade] trade
     * @apiParam (输入参数：) {string}        [trade_cn] trade_cn
     * @apiParam (输入参数：) {string}        [birthdate] birthdate
     * @apiParam (输入参数：) {string}        [residence] residence
     * @apiParam (输入参数：) {string}        [height] height
     * @apiParam (输入参数：) {string}        [marriage] marriage
     * @apiParam (输入参数：) {string}        [marriage_cn] marriage_cn
     * @apiParam (输入参数：) {string}        [experience] experience
     * @apiParam (输入参数：) {string}        [experience_cn] experience_cn
     * @apiParam (输入参数：) {string}        [district] district
     * @apiParam (输入参数：) {string}        [district_cn] district_cn
     * @apiParam (输入参数：) {string}        [wage] wage
     * @apiParam (输入参数：) {string}        [wage_cn] wage_cn
     * @apiParam (输入参数：) {string}        [householdaddress] householdaddress
     * @apiParam (输入参数：) {string}        [education] education
     * @apiParam (输入参数：) {string}        [education_cn] education_cn
     * @apiParam (输入参数：) {string}        [major] major
     * @apiParam (输入参数：) {string}        [major_cn] major_cn
     * @apiParam (输入参数：) {string}        [tag] tag
     * @apiParam (输入参数：) {string}        [tag_cn] tag_cn
     * @apiParam (输入参数：) {string}        [telephone] telephone
     * @apiParam (输入参数：) {string}        [email] email
     * @apiParam (输入参数：) {string}        [email_notify] email_notify
     * @apiParam (输入参数：) {string}        [intention_jobs_id] intention_jobs_id
     * @apiParam (输入参数：) {string}        [intention_jobs] intention_jobs
     * @apiParam (输入参数：) {string}        [specialty] specialty
     * @apiParam (输入参数：) {string}        [photo] photo
     * @apiParam (输入参数：) {string}        [photo_img] photo_img
     * @apiParam (输入参数：) {string}        [photo_audit] photo_audit
     * @apiParam (输入参数：) {string}        [photo_display] photo_display
     * @apiParam (输入参数：) {string}        [qq] qq
     * @apiParam (输入参数：) {string}        [weixin] weixin
     * @apiParam (输入参数：) {string}        [addtime] addtime
     * @apiParam (输入参数：) {string}        [refreshtime] refreshtime
     * @apiParam (输入参数：) {string}        [stime] stime
     * @apiParam (输入参数：) {string}        [entrust] entrust
     * @apiParam (输入参数：) {string}        [talent] talent
     * @apiParam (输入参数：) {string}        [level] level
     * @apiParam (输入参数：) {string}        [complete_percent] complete_percent
     * @apiParam (输入参数：) {string}        [current] current
     * @apiParam (输入参数：) {string}        [current_cn] current_cn
     * @apiParam (输入参数：) {string}        [word_resume] word_resume
     * @apiParam (输入参数：) {string}        [word_resume_title] word_resume_title
     * @apiParam (输入参数：) {string}        [word_resume_addtime] word_resume_addtime
     * @apiParam (输入参数：) {string}        [key_full] key_full
     * @apiParam (输入参数：) {string}        [key_precise] key_precise
     * @apiParam (输入参数：) {string}        [click] click
     * @apiParam (输入参数：) {string}        [tpl] tpl
     * @apiParam (输入参数：) {string}        [resume_from_pc] resume_from_pc
     * @apiParam (输入参数：) {string}        [def] def
     * @apiParam (输入参数：) {string}        [mobile_audit] mobile_audit
     * @apiParam (输入参数：) {string}        [comment_content] comment_content
     * @apiParam (输入参数：) {string}        [is_quick] is_quick
     * @apiParam (输入参数：) {string}        [idcard] 身份证号
     * @apiParam (输入参数：) {string}        [like_num] 点赞数
     * @apiParam (输入参数：) {string}        [subsite_id] subsite_id
     * @apiParam (输入参数：) {string}        [is_exsoliders] 是否退役军人 1-否 2-是
     * @apiParam (输入参数：) {string}        [is_exsoliders_family] 是否退役军人军属 1-否 2-是
     * @apiParam (输入参数：) {string}        [retireTime] 退役时间
     * @apiParam (输入参数：) {string}        [demand] 我的需求
     * @apiParam (输入参数：) {string}        [member_type] 求职群体  1普通   2退役军人   3军属
     * @apiParam (失败返回参数：) {object}        array 返回结果集
     * @apiParam (失败返回参数：) {string}        array.status 返回错误码 201
     * @apiParam (失败返回参数：) {string}        array.msg 返回错误消息
     * @apiParam (成功返回参数：) {string}        array 返回结果集
     * @apiParam (成功返回参数：) {string}        array.status 返回错误码 200
     * @apiParam (成功返回参数：) {string}        array.data 返回数据
     * @apiParam (成功返回参数：) {string}        array.data.list 返回数据列表
     * @apiParam (成功返回参数：) {string}        array.data.count 返回数据总数
     * @apiSuccessExample {json} 01 成功示例
     * {"status":"200","data":""}
     * @apiErrorExample {json} 02 失败示例
     * {"status":" 201","msg":"查询失败"}
     */
    function index()
    {
        $limit = $this->request->get('limit', 20, 'intval');
        $page = $this->request->get('page', 1, 'intval');

        $where = [];
        $where['uid'] = $this->request->get('uid', '', 'serach_in');
        $where['display'] = $this->request->get('display', '', 'serach_in');
        $where['display_name'] = $this->request->get('display_name', '', 'serach_in');
        $where['audit'] = $this->request->get('audit', '', 'serach_in');
        $where['stick'] = $this->request->get('stick', '', 'serach_in');
        $where['strong_tag'] = $this->request->get('strong_tag', '', 'serach_in');
        $where['title'] = $this->request->get('title', '', 'serach_in');
        $where['fullname'] = $this->request->get('fullname', '', 'serach_in');
        $where['sex'] = $this->request->get('sex', '', 'serach_in');
        $where['sex_cn'] = $this->request->get('sex_cn', '', 'serach_in');
        $where['nature'] = $this->request->get('nature', '', 'serach_in');
        $where['nature_cn'] = $this->request->get('nature_cn', '', 'serach_in');
        $where['trade'] = $this->request->get('trade', '', 'serach_in');
        $where['trade_cn'] = $this->request->get('trade_cn', '', 'serach_in');
        $where['birthdate'] = $this->request->get('birthdate', '', 'serach_in');
        $where['residence'] = $this->request->get('residence', '', 'serach_in');
        $where['height'] = $this->request->get('height', '', 'serach_in');
        $where['marriage'] = $this->request->get('marriage', '', 'serach_in');
        $where['marriage_cn'] = $this->request->get('marriage_cn', '', 'serach_in');
        $where['experience'] = $this->request->get('experience', '', 'serach_in');
        $where['experience_cn'] = $this->request->get('experience_cn', '', 'serach_in');
        $where['district'] = $this->request->get('district', '', 'serach_in');
        $where['district_cn'] = $this->request->get('district_cn', '', 'serach_in');
        $where['wage'] = $this->request->get('wage', '', 'serach_in');
        $where['wage_cn'] = $this->request->get('wage_cn', '', 'serach_in');
        $where['householdaddress'] = $this->request->get('householdaddress', '', 'serach_in');
        $where['education'] = $this->request->get('education', '', 'serach_in');
        $where['education_cn'] = $this->request->get('education_cn', '', 'serach_in');
        $where['major'] = $this->request->get('major', '', 'serach_in');
        $where['major_cn'] = $this->request->get('major_cn', '', 'serach_in');
        $where['tag'] = $this->request->get('tag', '', 'serach_in');
        $where['tag_cn'] = $this->request->get('tag_cn', '', 'serach_in');
        $where['telephone'] = $this->request->get('telephone', '', 'serach_in');
        $where['email'] = $this->request->get('email', '', 'serach_in');
        $where['email_notify'] = $this->request->get('email_notify', '', 'serach_in');
        $where['intention_jobs_id'] = $this->request->get('intention_jobs_id', '', 'serach_in');
        $where['intention_jobs'] = $this->request->get('intention_jobs', '', 'serach_in');
        $where['specialty'] = $this->request->get('specialty', '', 'serach_in');
        $where['photo'] = $this->request->get('photo', '', 'serach_in');
        $where['photo_img'] = $this->request->get('photo_img', '', 'serach_in');
        $where['photo_audit'] = $this->request->get('photo_audit', '', 'serach_in');
        $where['photo_display'] = $this->request->get('photo_display', '', 'serach_in');
        $where['qq'] = $this->request->get('qq', '', 'serach_in');
        $where['weixin'] = $this->request->get('weixin', '', 'serach_in');
        $where['addtime'] = $this->request->get('addtime', '', 'serach_in');
        $where['refreshtime'] = $this->request->get('refreshtime', '', 'serach_in');
        $where['stime'] = $this->request->get('stime', '', 'serach_in');
        $where['entrust'] = $this->request->get('entrust', '', 'serach_in');
        $where['talent'] = $this->request->get('talent', '', 'serach_in');
        $where['level'] = $this->request->get('level', '', 'serach_in');
        $where['complete_percent'] = $this->request->get('complete_percent', '', 'serach_in');
        $where['current'] = $this->request->get('current', '', 'serach_in');
        $where['current_cn'] = $this->request->get('current_cn', '', 'serach_in');
        $where['word_resume'] = $this->request->get('word_resume', '', 'serach_in');
        $where['word_resume_title'] = $this->request->get('word_resume_title', '', 'serach_in');
        $where['word_resume_addtime'] = $this->request->get('word_resume_addtime', '', 'serach_in');
        $where['key_full'] = $this->request->get('key_full', '', 'serach_in');
        $where['key_precise'] = $this->request->get('key_precise', '', 'serach_in');
        $where['click'] = $this->request->get('click', '', 'serach_in');
        $where['tpl'] = $this->request->get('tpl', '', 'serach_in');
        $where['resume_from_pc'] = $this->request->get('resume_from_pc', '', 'serach_in');
        $where['def'] = $this->request->get('def', '', 'serach_in');
        $where['mobile_audit'] = $this->request->get('mobile_audit', '', 'serach_in');
        $where['comment_content'] = $this->request->get('comment_content', '', 'serach_in');
        $where['is_quick'] = $this->request->get('is_quick', '', 'serach_in');
        $where['idcard'] = $this->request->get('idcard', '', 'serach_in');
        $where['like_num'] = $this->request->get('like_num', '', 'serach_in');
        $where['subsite_id'] = $this->request->get('subsite_id', '', 'serach_in');
        $where['is_exsoliders'] = $this->request->get('is_exsoliders', '', 'serach_in');
        $where['is_exsoliders_family'] = $this->request->get('is_exsoliders_family', '', 'serach_in');
        $where['retireTime'] = $this->request->get('retireTime', '', 'serach_in');
        $where['demand'] = $this->request->get('demand', '', 'serach_in');
        $where['member_type'] = $this->request->get('member_type', '', 'serach_in');

        $field = '*';
        $orderby = 'id desc';

        $res = ResumeService::indexList(formatWhere($where), $field, $orderby, $limit, $page);
        return $this->ajaxReturn($this->successCode, '返回成功', htmlOutList($res));
    }


    /**
     * @api {post} /Resume/delete 03、删除
     * @apiGroup Resume
     * @apiVersion 1.0.0
     * @apiDescription  删除
     * @apiHeader {String} Authorization 用户授权token
     * @apiHeaderExample {json} Header-示例:
     * "Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOjM2NzgsImF1ZGllbmNlIjoid2ViIiwib3BlbkFJZCI6MTM2NywiY3JlYXRlZCI6MTUzMzg3OTM2ODA0Nywicm9sZXMiOiJVU0VSIiwiZXhwIjoxNTM0NDg0MTY4fQ.Gl5L-NpuwhjuPXFuhPax8ak5c64skjDTCBC64N_QdKQ2VT-zZeceuzXB9TqaYJuhkwNYEhrV3pUx1zhMWG7Org"
     * @apiParam (输入参数：) {string}            ids 主键id 注意后面跟了s 多数据删除
     * @apiParam (失败返回参数：) {object}        array 返回结果集
     * @apiParam (失败返回参数：) {string}        array.status 返回错误码 201
     * @apiParam (失败返回参数：) {string}        array.msg 返回错误消息
     * @apiParam (成功返回参数：) {string}        array 返回结果集
     * @apiParam (成功返回参数：) {string}        array.status 返回错误码 200
     * @apiParam (成功返回参数：) {string}        array.msg 返回成功消息
     * @apiSuccessExample {json} 01 成功示例
     * {"status":"200","msg":"操作成功"}
     * @apiErrorExample {json} 02 失败示例
     * {"status":"201","msg":"操作失败"}
     */
    function delete()
    {
        $idx = $this->request->post('ids', '', 'serach_in');
        if (empty($idx)) {
            throw new ValidateException('参数错误');
        }
        $data['id'] = explode(',', $idx);
        try {
            ResumeModel::destroy($data, true);
        } catch (\Exception $e) {
            abort(config('my.error_log_code'), $e->getMessage());
        }
        return $this->ajaxReturn($this->successCode, '操作成功');
    }

    /**
     * @api {get} /Resume/view 04、查看详情
     * @apiGroup Resume
     * @apiVersion 1.0.0
     * @apiDescription  查看详情
     * @apiParam (输入参数：) {string}            id 主键ID
     * @apiHeader {String} Authorization 用户授权token
     * @apiHeaderExample {json} Header-示例:
     * "Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOjM2NzgsImF1ZGllbmNlIjoid2ViIiwib3BlbkFJZCI6MTM2NywiY3JlYXRlZCI6MTUzMzg3OTM2ODA0Nywicm9sZXMiOiJVU0VSIiwiZXhwIjoxNTM0NDg0MTY4fQ.Gl5L-NpuwhjuPXFuhPax8ak5c64skjDTCBC64N_QdKQ2VT-zZeceuzXB9TqaYJuhkwNYEhrV3pUx1zhMWG7Org"
     * @apiParam (失败返回参数：) {object}        array 返回结果集
     * @apiParam (失败返回参数：) {string}        array.status 返回错误码 201
     * @apiParam (失败返回参数：) {string}        array.msg 返回错误消息
     * @apiParam (成功返回参数：) {string}        array 返回结果集
     * @apiParam (成功返回参数：) {string}        array.status 返回错误码 200
     * @apiParam (成功返回参数：) {string}        array.data 返回数据详情
     * @apiSuccessExample {json} 01 成功示例
     * {"status":"200","data":""}
     * @apiErrorExample {json} 02 失败示例
     * {"status":"201","msg":"没有数据"}
     */
    function view()
    {
        $data['id'] = $this->request->get('id', '', 'serach_in');
        $field = 'id,uid,display,display_name,audit,stick,strong_tag,title,fullname,sex,sex_cn,nature,nature_cn,trade,trade_cn,birthdate,residence,height,marriage,marriage_cn,experience,experience_cn,district,district_cn,wage,wage_cn,householdaddress,education,education_cn,major,major_cn,tag,tag_cn,telephone,email,email_notify,intention_jobs_id,intention_jobs,specialty,photo,photo_img,photo_audit,photo_display,qq,weixin,addtime,refreshtime,stime,entrust,talent,level,complete_percent,current,current_cn,word_resume,word_resume_title,word_resume_addtime,key_full,key_precise,click,tpl,resume_from_pc,def,mobile_audit,comment_content,is_quick,idcard,like_num,subsite_id,is_exsoliders,is_exsoliders_family,retireTime,demand,member_type';
        $res = checkData(ResumeModel::field($field)->where($data)->find());
        return $this->ajaxReturn($this->successCode, '返回成功', $res);
    }

    /*start*/
    /**
     * @api {post} /Resume/add 05、添加
     */
    function add()
    {
        $postField = "fullname,sex,telephone,age,education,education_cn,intention_jobs_id,district,district_cn,member_type,work_status,work_year";
        $data = $this->request->only(explode(',', $postField), 'post', null);
        $data["uid"] = $this->request->uid;
        $data["district"] = implode(".", json_decode(htmlspecialchars_decode($data["district"]), true));
        $intention_jobs_id = json_decode(htmlspecialchars_decode($data["intention_jobs_id"]), true);
        $intention_jobs = \app\api\model\Categoryjobs::whereIn("id", $intention_jobs_id)->column('categoryname');
        $data["intention_jobs_id"] = implode(".", $intention_jobs_id);
        $data["intention_jobs"] = implode(".", $intention_jobs);


        $data["display"] = 1;
        $data["display_name"] = "1";
        $data["audit"] = 1;
        $data["stick"] = 0;
        $data["strong_tag"] = 0;
        $data["title"] = "默认简历";
        $data["sex_cn"] = $data["sex"] == 1 ? "男" : "女";
        $data["trade"] = "";
        $data["trade_cn"] = "";


        $data["nature"] = "62";
        $data["nature_cn"] = "全职";
        $data["birthdate"] = intval(date("Y"), time()) - $data["age"];
        $data["residence"] = "";
        $data["height"] = 170;
        $data["marriage"] = 3;
        $data["marriage_cn"] = "保密";

        $data["experience"] = "";
        $data["experience_cn"] = "";
        $data["wage"] = "55";
        $data["wage_cn"] = "面议";
        $data["householdaddress"] = "";
        $data["major"] = 0;
        $data["major_cn"] = "";
        $data["tag"] = "";
        $data["tag_cn"] = "";
//        $data["telephone"] = substr($data["telephone"], 0, 3) . str_repeat("*", 6) . substr($data["telephone"], -3); // 添加*后的手机号;

        $data["email"] = "";
        $data["email_notify"] = 0;

        $data["specialty"] = "";
        $data["photo"] = 0;
        $data["photo_img"] = "";
        $data["photo_audit"] = 1;
        $data["photo_display"] = 1;
        $data["qq"] = "";
        $data["weixin"] = "";

        $data["addtime"] = time();
        $data["refreshtime"] = time();
        $data["stime"] = 0;
        $data["entrust"] = 0;
        $data["talent"] = 1;
        $data["level"] = 1;
        $data["complete_percent"] = 50;
        $data["current"] = 0;
        $data["current_cn"] = "";

        $data["word_resume"] = "";
        $data["word_resume_title"] = "";
        $data["word_resume_addtime"] = 0;
        $data["key_full"] = "";
        $data["key_precise"] = "";
        $data["click"] = 0;
        $data["tpl"] = "";
        $data["resume_from_pc"] = 0;
        $data["def"] = 1;
        $data["mobile_audit"] = 0;
        $data["comment_content"] = "";
        $data["is_quick"] = 0;
        $data["idcard"] = "";
        $data["like_num"] = 0;
        $data["subsite_id"] = 1;
        $data["is_exsoliders"] = 1;
        $data["is_exsoliders_family"] = 1;
        $data["retireTime"] = "";
        $data["demand"] = "";
        $res = ResumeService::add($data);
        return $this->ajaxReturn($this->successCode, '操作成功', $res);
    }

    /**
     * @api {post} /Resume/update 02、修改
     */
    function update()
    {
        $postField = "id,fullname,sex,telephone,age,education,education_cn,intention_jobs_id,district,district_cn,member_type,work_status,work_year";
        $data = $this->request->only(explode(',', $postField), 'post', null);
        if (empty($data['id'])) {
            throw new ValidateException('参数错误');
        }
        $where['id'] = $data['id'];
        $data = $this->request->only(explode(',', $postField), 'post', null);
        $data["district"] = implode(".", json_decode(htmlspecialchars_decode($data["district"]), true));
        $intention_jobs_id = json_decode(htmlspecialchars_decode($data["intention_jobs_id"]), true);
        $intention_jobs = \app\api\model\Categoryjobs::whereIn("id", $intention_jobs_id)->column('categoryname');
        $data["intention_jobs_id"] = implode(".", $intention_jobs_id);
        $data["intention_jobs"] = implode(".", $intention_jobs);

        $data["sex_cn"] = $data["sex"] == 1 ? "男" : "女";
        $data["birthdate"] = intval(date("Y"), time()) - $data["age"];
        //$data["telephone"] = substr($data["telephone"], 0, 3) . str_repeat("*", 6) . substr($data["telephone"], -3); // 添加*后的手机号;
        $res = ResumeService::update($where, $data);
        return $this->ajaxReturn($this->successCode, '操作成功', $res);
    }

    /**
     * @api {get} /Resume/myResume 06、我的简历
     */
    function myResume()
    {
        $uid = $this->request->uid;
        $res = ResumeModel::with("work")->where("uid", $uid)->order("id DESC")->findOrEmpty()->toArray();
        if (empty($res)) {
            $res['id'] = 0;
        } else {
            if (empty($res["work"])) $res["work"] = [];
            $res["district"] = explode(".", $res["district"]);
            $res["intention_jobs_id"] = explode(".", $res["intention_jobs_id"]);
            foreach ($res["intention_jobs_id"] as &$v) {
                $v = intval($v);
            }
            unset($v);
            $res["intention_jobs"] = explode(".", $res["intention_jobs"]);
            $district_cn = [];
            $district = CategorydistrictModel::whereIn("id", $res["district"])->column('categoryname', "id");
            if (!empty($res["district"])) {
                foreach ($res["district"] as &$v) {
                    $v = intval($v);
                    if (!empty($v)) {
                        $district_cn[] = $district[$v];
                    } else {
                        $district_cn[] = "";
                    }
                }
            }
            $res["district_cn"] = $district_cn;
            $res["member_type_cn"] = memberType($res["member_type"]);
            $res["member_type_cn"] = $res["member_type_cn"]["c_name"];
        }
        return $this->ajaxReturn($this->successCode, '返回成功', $res);
    }
    /*end*/

}

